package com.cat.greedyAlgorithm;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/maximum-matching-of-players-with-trainers/
 * @create 2025/8/23 10:36
 * @since JDK17
 */

public class Solution21 {
    public int matchPlayersAndTrainers(int[] players, int[] trainers) {
        Arrays.sort(players);
        Arrays.sort(trainers);
        int ans = 0, n = players.length, m = trainers.length;
        for (int i = 0, j = 0; i < n; i++) {
            while (j < m && trainers[j] < players[i]) {
                j++;
            }
            if (j == m) {
                break;
            } else {
                j++;
                ans++;
            }
        }
        return ans;
    }
}
